package com.vertexnet.realestatenet.model.bean;

// Generated Jun 16, 2012 6:32:09 PM by Hibernate Tools 3.4.0.CR1

import static javax.persistence.GenerationType.IDENTITY;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

/**
 * Site generated by hbm2java
 */
@Entity
@Table(name = "site", catalog = "real_estate_net", uniqueConstraints = @UniqueConstraint(columnNames = "purchase_id"))
public class Site implements java.io.Serializable {

	private static final long serialVersionUID = 1L;
	private Integer siteId;
	private Customer customer;
	private Layout layout;
	private PaymentPlan paymentPlan;
	private int purchaseId;
	private Date paymentStartDate;
	private Set<Payment> payments = new HashSet<Payment>(0);

	public Site() {
	}

	public Site(int siteId, Customer customer, Layout layout, PaymentPlan paymentPlan, int purchaseId, Date paymentStartDate) {
		this.siteId = siteId;
		this.customer = customer;
		this.layout = layout;
		this.paymentPlan = paymentPlan;
		this.purchaseId = purchaseId;
		this.paymentStartDate = paymentStartDate;
	}

	public Site(int siteId, Customer customer, Layout layout, PaymentPlan paymentPlan, int purchaseId, Date paymentStartDate, Set<Payment> payments) {
		this.siteId = siteId;
		this.customer = customer;
		this.layout = layout;
		this.paymentPlan = paymentPlan;
		this.purchaseId = purchaseId;
		this.paymentStartDate = paymentStartDate;
		this.payments = payments;
	}

	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "site_id", unique = true, nullable = false)
	public Integer getSiteId() {
		return this.siteId;
	}

	public void setSiteId(Integer siteId) {
		this.siteId = siteId;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "customer_id", nullable = false)
	public Customer getCustomer() {
		return this.customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "layout_id", nullable = false)
	public Layout getLayout() {
		return this.layout;
	}

	public void setLayout(Layout layout) {
		this.layout = layout;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "plan_id", nullable = false)
	public PaymentPlan getPaymentPlan() {
		return this.paymentPlan;
	}

	public void setPaymentPlan(PaymentPlan paymentPlan) {
		this.paymentPlan = paymentPlan;
	}

	@Column(name = "purchase_id", unique = true, nullable = false)
	public int getPurchaseId() {
		return this.purchaseId;
	}

	public void setPurchaseId(int purchaseId) {
		this.purchaseId = purchaseId;
	}

	@Temporal(TemporalType.DATE)
	@Column(name = "payment_start_date", nullable = false, length = 10)
	public Date getPaymentStartDate() {
		return this.paymentStartDate;
	}

	public void setPaymentStartDate(Date paymentStartDate) {
		this.paymentStartDate = paymentStartDate;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "site", orphanRemoval=true)
	@NotFound(action = NotFoundAction.IGNORE)
	public Set<Payment> getPayments() {
		return this.payments;
	}

	public void setPayments(Set<Payment> payments) {
		this.payments = payments;
	}

	@Override
	public boolean equals(Object obj) {
		if(obj == null) {
			return false;
		}
		if(obj instanceof Site) {
			Site site = (Site) obj;
			return new EqualsBuilder()
			.append(this.getSiteId(), site.getSiteId())
			.append(this.getPurchaseId(), site.getPurchaseId())
			.isEquals();
		}
		return false;
	}

	@Override
	public int hashCode() {
		 return new HashCodeBuilder()
		.append(this.getSiteId())
		.append(this.getPurchaseId())
		.append(this.getPaymentStartDate())
		.toHashCode();
	}

	@Override
	public String toString() {
		return Integer.toString(this.getPurchaseId());
	}
}
